/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
/**
 *
 */
package com.eelpo.cmmp.uac.dao.impl;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.eelpo.cmmp.core.spring.orm.jpa.BasicCommonDao;
import com.eelpo.cmmp.uac.dao.IEnterpriseManageDao;
import com.eelpo.cmmp.uac.dao.entity.TEnterprise;
import com.eelpo.common.query.Join;
import com.eelpo.common.query.JpaCriteria;
import com.eelpo.common.query.Order;
import com.eelpo.common.query.Result;
import com.eelpo.common.query.criteria.Criteria;

/**
 * <pre>
 * 
 * 
 * 
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
@Repository
public class EnterpriseManageDao extends BasicCommonDao implements IEnterpriseManageDao {

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#getEnterpriseById(java.lang.String)
	 */
	@Override
	public TEnterprise getEnterpriseById(String id) throws DataAccessException {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#getEnterpriseByName(java.lang.String)
	 */
	@Override
	public TEnterprise getEnterpriseByName(String name) throws DataAccessException {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#checkExist(java.lang.String)
	 */
	@Override
	public boolean checkExist(String name) throws DataAccessException {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#checkExistByUpdate(java.lang.String,
	 *      java.lang.String)
	 */
	@Override
	public boolean checkExistByUpdate(String id, String name) throws DataAccessException {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#addEnterprise(com.eelpo.cmmp.uac.dao.enterprise.TEnterprise)
	 */
	@Override
	public String addEnterprise(TEnterprise enterprise) throws DataAccessException {
		persist(enterprise);
		return enterprise.getId();
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#updateEnterprise(com.eelpo.cmmp.uac.dao.enterprise.TEnterprise)
	 */
	@Override
	public void updateEnterprise(TEnterprise enterprise) throws DataAccessException {
		// TODO Auto-generated method stub

	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#deleteEnterprise(java.lang.String)
	 */
	@Override
	public void deleteEnterprise(String id) throws DataAccessException {
		// TODO Auto-generated method stub

	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#getEnterprises()
	 */
	@Override
	public List<TEnterprise> getEnterprises() throws DataAccessException {
		Criteria criteria = JpaCriteria.create(TEnterprise.class, "e");
		criteria.result(Result.result());
		criteria.join(Join.leftJoinFetch("parent p"));
		criteria.join(Join.leftJoinFetch("parentRelation r"));
		criteria.order(Order.asc("index"));
		return getResultList(criteria);
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see com.eelpo.cmmp.uac.dao.IEnterpriseManageDao#getEnterprises(java.lang.String)
	 */
	@Override
	public List<TEnterprise> getEnterprises(String userId) throws DataAccessException {
		// TODO Auto-generated method stub
		return null;
	}

}
